package controllers

import (
	"github.com/astaxie/beego"
	"datapro/models"
	"HTdatapro/htmodels"
)

type MainController struct {
	beego.Controller
}

func (c *MainController) Get() {
	c.TplName = "index.html"
}

func (c *MainController) Index_v1() {
	c.TplName = "index_v1.html"
}
func (c *MainController)Login() {
	if uid := c.GetSession("uid"); uid != nil {
		c.Redirect("/", 302)
	}
	phone := c.GetString("user")
	pass := c.GetString("pass")
	if phone == "admin@admin.com" {
		if pass == "admin123" {
			c.SetSession("uid", 0)
			c.SetSession("utype", 1000)
			c.Redirect("/", 302)
		}
	}
	if phone != "" {
		user := models.User{UserName:phone}
		if htmodels.HTCheckUserLogin(&user, pass) {
			c.SetSession("uid", user.Id)
			c.SetSession("utype", user.UserType)
			c.SetSession("uname",user.NickName)
			c.Redirect("/hd/node/parentlist", 302)
		} else {
			c.Data["wronginfo"] = true
		}
	}

	c.TplName = "login.html"
}

func (c *MainController)Logout() {
	c.DelSession("uid")
	c.DelSession("utype")
	c.Redirect("/login", 302)
}